{% import 'macro/svg.html' as SVG %}
{% import 'macro/oops.html' as OOPS %}
<div class="container-xl">
  <!-- Page title -->
  <div class="page-header d-print-none">
    <div class="row align-items-center">
      <div class="col">
        <h2 class="page-title">
          自动删种任务
        </h2>
      </div>
      <div class="col-auto ms-auto d-print-none">
        <div class="btn-list">
          <a href="javascript:show_add_torrent_remove_task_modal()" class="btn btn-primary d-none d-sm-inline-block">
            {{ SVG.plus() }}
            新增删种任务
          </a>
          <a href="javascript:show_add_torrent_remove_task_modal()" class="btn btn-primary d-sm-none btn-icon">
            {{ SVG.plus() }}
          </a>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 业务页面代码 -->
{% if Count > 0 %}
<div class="page-body">
  <div class="container-xl">
    <div class="row row-cards">
      {% for Id, Attr in TorrentRemoveTasks.items() %}
      <div class="card">
        <div class="card-header">
          <a href="javascript:$(`#detail_{{ Attr.id }}`).slideToggle()"
             title="展开/折叠"  data-bs-toggle="tooltip">
            <div>
              {% if Attr.enabled %}
              <span class="badge bg-green"></span>
              {% else %}
              <span class="badge bg-red"></span>
              {% endif %}
            </div>
          </a>
          <a href="javascript:$(`#detail_{{ Attr.id }}`).slideToggle()" style="text-decoration-line: none; color: unset"
             title="展开/折叠" data-bs-toggle="tooltip">
            <div class="ms-3">
                <h3 class="card-title">{{ Attr.name }}</h3>
            </div>
          </a>
          <div class="ms-2 d-none d-sm-block">
            <a href="javascript:run_torrent_remove_now('{{ Attr.id }}')" class="btn-icon" title="立即运行任务"
              data-bs-toggle="tooltip">
              {{ SVG.bolt('icon-filled') }}
            </a>
          </div>
          <a href="#" class="link-secondary ms-auto d-sm-none" data-bs-toggle="dropdown" aria-expanded="false">
            {{ SVG.dots() }}
          </a>
          <div class="dropdown-menu dropdown-menu-end">
            <button class="dropdown-item text-info" onclick="run_torrent_remove_now('{{ Attr.id }}')">
              立即运行
            </button>
            <button class="dropdown-item" onclick="show_remove_torrents_modal('{{ Attr.id }}')">
              预览
            </button>
            <button class="dropdown-item" onclick="show_edit_torrent_remove_task_modal('{{ Attr.id }}')">
              编辑
            </button>
            <button class="dropdown-item text-danger" onclick="delete_torrent_remove_task('{{ Attr.id }}', '{{ Attr.name }}')">
              删除
            </button>
          </div>
          <div class="card-actions btn-actions d-none d-sm-block">
            <a href="javascript:$(`#detail_{{ Attr.id }}`).slideToggle()" class="btn-action"
               title="展开/折叠" data-bs-toggle="tooltip">
              {{ SVG.menu_2() }}
            </a>
            <a href="javascript:show_remove_torrents_modal('{{ Attr.id }}')" class="btn-action"
               title="预览删种" data-bs-toggle="tooltip">
              {{ SVG.eye() }}
            </a>
            <a href="javascript:show_edit_torrent_remove_task_modal('{{ Attr.id }}')" class="btn-action"
               title="编辑设置" data-bs-toggle="tooltip">
              {{ SVG.edit() }}
            </a>
            <a href="javascript:delete_torrent_remove_task('{{ Attr.id }}', '{{ Attr.name }}')" class="btn-action"
               title="删除设置" data-bs-toggle="tooltip">
              {{ SVG.x() }}
            </a>
          </div>
        </div>
        <div class="card-body" id="detail_{{ Attr.id }}"
            style="display: {% if Count > 3 %}none{% else %}block{% endif %};">
          <div class="datagrid">
            <div class="datagrid-item">
              <div class="datagrid-title">下载器</div>
              <div class="datagrid-content">
                <span class="badge me-2 bg-blue">{{ DownloaderConfig[Attr.downloader].name}}</span>
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">管理限制</div>
              <div class="datagrid-content">
              {% if Attr.onlynastool %}
                <span class="badge me-2">只管理NAStool添加</span>
              {% endif %}
              {% if Attr.samedata %}
                <span class="badge me-2">处理辅种</span>
              {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">刷新间隔</div>
              <div class="datagrid-content">
                {{ Attr.interval }} 分钟
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">动作</div>
              <div class="datagrid-content">
                {% if Attr.action == 1 %}
                <span class="badge me-2 bg-blue">暂停任务</span>
                {% elif Attr.action == 2 %}
                <span class="badge me-2 bg-orange">删除任务</span>
                {% elif Attr.action == 3 %}
                <span class="badge me-2 bg-red">删除任务及文件</span>
                {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">分享率</div>
              <div class="datagrid-content">
              {% if Attr.config.ratio %}
                {{ Attr.config.ratio }} +
              {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">做种时间</div>
              <div class="datagrid-content">
              {% if Attr.config.seeding_time %}
                {{ Attr.config.seeding_time }} 小时 +
              {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">平均做种速度</div>
              <div class="datagrid-content">
              {% if Attr.config.upload_avs %}
                {{ Attr.config.upload_avs }} KB/s -
              {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">大小</div>
              <div class="datagrid-content">
              {% if Attr.config.size %}
                {{ Attr.config.size[0] }}-{{ Attr.config.size[-1] }} GB
              {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">保存路径关键词</div>
              <div class="datagrid-content">
              {% if Attr.config.savepath_key %}
                <span class="badge me-2 bg-orange">{{ Attr.config.savepath_key }}</span>
              {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">tracker关键词</div>
              <div class="datagrid-content">
              {% if Attr.config.tracker_key %}
                <span class="badge me-2 bg-orange">{{ Attr.config.tracker_key }}</span>
              {% endif %}
              </div>
            </div>
            {% if Attr.downloader == "Qb" %}
              <div class="datagrid-item">
                <div class="datagrid-title">分类</div>
                <div class="datagrid-content">
                  {% if Attr.config.qb_category %}
                  {% for Category in Attr.config.qb_category %}
                  <span class="badge me-2 mb-1">{{ Category }}</span>
                  {% endfor %}
                  {% endif %}
                </div>
              </div>
              <div class="datagrid-item">
                <div class="datagrid-title">种子状态</div>
                <div class="datagrid-content">
                  {% if Attr.config.qb_state %}
                  {% for State in Attr.config.qb_state %}
                  <span class="badge me-2 bg-blue mb-1">{{ State }}</span>
                  {% endfor %}
                  {% endif %}
                </div>
              </div>
            {% elif Attr.downloader == "Tr" %}
              <div class="datagrid-item">
                <div class="datagrid-title">错误信息关键词</div>
                <div class="datagrid-content">
                {% if Attr.config.tr_error_key %}
                  <span class="badge me-2 bg-orange">{{ Attr.config.tr_error_key }}</span>
                {% endif %}
                </div>
              </div>
              <div class="datagrid-item">
                <div class="datagrid-title">种子状态</div>
                <div class="datagrid-content">
                  {% if Attr.config.tr_state %}
                  {% for State in Attr.config.tr_state %}
                  <span class="badge me-2 bg-blue mb-1">{{ State }}</span>
                  {% endfor %}
                  {% endif %}
                </div>
              </div>
            {% endif %}
            <div class="datagrid-item">
              <div class="datagrid-title">状态</div>
              <div class="datagrid-content">
                {% if Attr.enabled %}
                <span class="badge me-2 bg-green">正在运行</span>
                {% else %}
                <span class="badge me-2 bg-red">已停用</span>
                {% endif %}
              </div>
            </div>
            <div class="datagrid-item">
              <div class="datagrid-title">标签</div>
              <div class="datagrid-content">
                {% if Attr.config.tags %}
                {% for Tag in Attr.config.tags %}
                <span class="badge me-2 mb-1">{{ Tag }}</span>
                {% endfor %}
                {% endif %}
              </div>
            </div>
          </div>
        </div>
      </div>
      {% endfor %}
    </div>
  </div>
</div>
{% else %}
{{ OOPS.nodatafound('没有任务', '当前没有正在运行的自动删种任务。') }}
{% endif %}
<div class="modal modal-blur fade" id="modal-torrent-remove-task" tabindex="-1" role="dialog" aria-hidden="true"
  data-bs-backdrop="static" data-bs-keyboard="false">
  <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modal-torrent-remove-task-title">新增删种任务</h5>
        <input type="hidden" id="torrent_remove_task_id" />
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label required">名称</label>
              <input type="text" id="name" class="form-control" placeholder="别名">
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">动作</label>
              <select class="form-select" id="action">
                <option value="1" selected>暂停种子</option>
                <option value="2">删除种子</option>
                <option value="3">删除种子及文件</option>
              </select>
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label required">运行间隔（分钟） <span class="form-help" title="执行自动删种任务的间隔时间"
                  data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="interval" class="form-control" placeholder="分钟">
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">状态</label>
              <select class="form-select" id="enabled">
                <option value="1">启用</option>
                <option value="0" selected>停用</option>
              </select>
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">处理辅种 <span class="form-help" title="若种子名称及大小与满足其他删种条件的种子相同，则一并处理"
                  data-bs-toggle="tooltip">?</span></label>
              <select class="form-select" id="samedata">
                <option value="0" selected>否</option>
                <option value="1" >是</option>
              </select>
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">只管理NAStool添加的下载 <span class="form-help" title="只管理含有NASTOOL标签的种子"
                  data-bs-toggle="tooltip">?</span></label>
              <select class="form-select" id="onlynastool">
                <option value="0">否</option>
                <option value="1" selected>是</option>
              </select>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">分享率 <span class="form-help" title="种子分享率大于等于设置值视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="ratio" class="form-control" placeholder="保留一位小数">
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">做种时间 <span class="form-help" title="种子做种时间大于等于设置值视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="seeding_time" class="form-control" placeholder="小时">
            </div>
          </div>
          <div class="col-lg-4">
            <div class="mb-3">
              <label class="form-label">平均上传速度 <span class="form-help" title="种子平均上传速度小于等于设置值视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="upload_avs" class="form-control" placeholder="KB/s">
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-lg-3">
            <div class="mb-3">
              <label class="form-label">种子大小 <span class="form-help" title="种子大小在设置范围内视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="size" class="form-control" placeholder="GB，例如如1-10">
            </div>
          </div>
          <div class="col-lg-9">
            <div class="mb-3">
              <label class="form-label">标签 <span class="form-help" title="设置多个标签时，种子包含所有标签视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="tags" class="form-control" placeholder="多个标签用;分隔">
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-lg-6">
            <div class="mb-3">
              <label class="form-label">保存路径关键词 <span class="form-help" title="种子保存路径含有关键词视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="savepath_key" class="form-control" placeholder="支持正则表达式">
            </div>
          </div>
          <div class="col-lg-6">
            <div class="mb-3">
              <label class="form-label">tracker关键词 <span class="form-help" title="种子第一个活动tracker含有关键词视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="tracker_key" class="form-control" placeholder="支持正则表达式">
            </div>
          </div>
        </div>
        <div class="form-selectgroup-boxes row mb-3">
          <label class="form-label required">下载器</label>
          {% for Id, Attr in DownloaderConfig.items() %}
          <div class="col-lg-6">
            <div class="mb-1">
              <label class="form-selectgroup-item" for="downloader_{{ Id }}">
                <input type="radio" name="downloader" id="downloader_{{ Id }}" value="{{ Id }}" class="form-selectgroup-input" checked>
                <span class="form-selectgroup-label d-flex align-items-center p-3">
                  <span class="me-3">
                    <span class="form-selectgroup-check"></span>
                  </span>
                  <span class="form-selectgroup-label-content">
                    <span class="avatar avatar-sm avatar-thumb avatar-rounded"
                          style="background-image: url({{ Attr.img_url }})"></span>
                    <span class="form-selectgroup-title strong mb-1">&nbsp;&nbsp;&nbsp;{{ Attr.name }}</span>
                  </span>
                </span>
              </label>
            </div>
          </div>
          {% endfor %}
        </div>
        <div id="qb_config_div" class="row">
          <div class="col-lg-7">
            <div class="mb-3">
              <label class="form-label">种子状态 <span class="form-help"
                title=
                "{% for Id, Attr in DownloaderConfig.Qb.torrent_state.items() %}
                {{ Id }}：{{ Attr }}<br>
                {% endfor %}
                <br>设置多个状态时，种子属于其中任一状态视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip"
                data-bs-html="true">?</span></label>
              <input type="text" id="qb_state" class="form-control" placeholder="多个状态用;分隔">
            </div>
          </div>
          <div class="col-lg-5">
            <div class="mb-3">
              <label class="form-label">分类 <span class="form-help" title="设置多个分类时，种子属于其中任一分类视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="qb_category" class="form-control" placeholder="多个分类用;分隔">
            </div>
          </div>
        </div>
        <div id="tr_config_div" class="row">
          <div class="col-lg-7">
            <div class="mb-3">
              <label class="form-label">种子状态 <span class="form-help"
                title="{% for Id, Attr in DownloaderConfig.Tr.torrent_state.items() %}
                {{ Id }}：{{ Attr }}<br>
                {% endfor %}
                <br>设置多个状态时，种子属于其中任一状态视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip"
                data-bs-html="true">?</span></label>
              <input type="text" id="tr_state" class="form-control" placeholder="多个状态用;分隔">
            </div>
          </div>
          <div class="col-lg-5">
            <div class="mb-3">
              <label class="form-label">错误信息关键词 <span class="form-help" title="种子错误信息含有关键词视为满足该条件，留空为不启用"
                data-bs-toggle="tooltip">?</span></label>
              <input type="text" id="tr_error_key" class="form-control" placeholder="支持正则表达式">
            </div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button id="download_setting_close_btn" class="btn btn-link" data-bs-dismiss="modal">
          取消
        </button>
        <button id="add_or_edit_torrent_remove_task_btn" class="btn btn-primary ms-auto"
          onclick="add_or_edit_torrent_remove_task()">
          保存
        </button>
      </div>
    </div>
  </div>
</div>
<div class="modal modal-blur fade" id="modal-remove-torrents" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">预处理种子列表</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="table-responsive" style="overflow-y: auto; max-height: 35em;">
        <table id="table-remove-torrents" class="table table-vcenter card-table">
        </table>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">

  // 显示新增任务
  function show_add_torrent_remove_task_modal(){
    $("#torrent_remove_task_id").val('');
    $("#modal-torrent-remove-task-title").val('新增删种任务');
    $("#name").val('');
    $("#action").val('1');
    $("#interval").val('');
    $("#enabled").val('0');
    $("#samedata").val('0');
    $("#onlynastool").val('1');
    $("#size").val('');
    $("#ratio").val('');
    $("#seeding_time").val('');
    $("#upload_avs").val('');
    $("#tags").val('');
    $("#savepath_key").val('');
    $("#tracker_key").val('');
    show_downloader("Qb");
    $("#qb_category").val('');
    $("#qb_state").val('');
    $("#tr_error_key").val('');
    $("#tr_state").val('');
    $("#modal-torrent-remove-task").modal('show');
  }

  // 显示编辑任务
  function show_edit_torrent_remove_task_modal(tid){
    $("#torrent_remove_task_id").val(tid);
    ajax_post("get_torrent_remove_task", { tid: tid }, function (ret) {
      if (ret.code == 0) {
        $("#modal-download-setting-title").val('编辑下载设置');
        $("#name").val(ret.detail.name);
        $("#action").val(ret.detail.action);
        $("#interval").val(ret.detail.interval);
        $("#enabled").val(ret.detail.enabled);
        $("#samedata").val(ret.detail.samedata);
        $("#onlynastool").val(ret.detail.onlynastool);
        if (ret.detail.config.size.length) {
          let minsize = ret.detail.config.size[0];
          let maxsize = ret.detail.config.size[1];
          $("#size").val(`${minsize}-${maxsize}`);
        } else {
          $("#size").val('');
        }
        if (ret.detail.config.ratio) {
          $("#ratio").val(ret.detail.config.ratio);
        } else {
          $("#ratio").val('');
        }
        if (ret.detail.config.seeding_time) {
          $("#seeding_time").val(ret.detail.config.seeding_time);
        } else {
          $("#seeding_time").val('');
        }
        if (ret.detail.config.upload_avs) {
          $("#upload_avs").val(ret.detail.config.upload_avs);
        } else {
          $("#upload_avs").val('');
        }
        $("#tags").val(ret.detail.config.tags.join(';'));
        $("#savepath_key").val(ret.detail.config.savepath_key);
        $("#tracker_key").val(ret.detail.config.tracker_key);
        show_downloader(ret.detail.downloader);
        if (ret.detail.downloader == "Qb") {
          $("#qb_category").val(ret.detail.config.qb_category.join(';'));
          $("#qb_state").val(ret.detail.config.qb_state.join(';'));
          $("#tr_error_key").val('');
          $("#tr_state").val('');
        } else if (ret.detail.downloader == "Tr") {
          $("#qb_category").val('');
          $("#qb_state").val('');
          $("#tr_error_key").val(ret.detail.config.tr_error_key);
          $("#tr_state").val(ret.detail.config.tr_state.join(';'));
        }
        $("#modal-torrent-remove-task").modal('show');
      }
    });
  }

  // 保存新建/编辑任务
  function add_or_edit_torrent_remove_task(){
    let tid = $("#torrent_remove_task_id").val();
    let name = $("#name").val();
    if (!name) {
      $("#name").addClass("is-invalid");
      return;
    } else {
      $("#name").removeClass("is-invalid");
    }
    let interval = $("#interval").val();
    if (!interval || isNaN(interval)) {
      $("#interval").addClass("is-invalid");
      return;
    } else {
      $("#interval").removeClass("is-invalid");
    }
    let ratio = $("#ratio").val();
    if (ratio && isNaN(ratio)) {
      $("#ratio").addClass("is-invalid");
      return;
    } else {
      $("#ratio").removeClass("is-invalid");
    }
    let seeding_time = $("#seeding_time").val();
    if (seeding_time && isNaN(seeding_time)) {
      $("#seeding_time").addClass("is-invalid");
      return;
    } else {
      $("#seeding_time").removeClass("is-invalid");
    }
    let upload_avs = $("#upload_avs").val();
    if (upload_avs && isNaN(upload_avs)) {
      $("#upload_avs").addClass("is-invalid");
      return;
    } else {
      $("#upload_avs").removeClass("is-invalid");
    }
    let params = {
      tid: tid,
      name: name,
      action: $("#action").val(),
      interval: interval,
      enabled: $("#enabled").val(),
      samedata: $("#samedata").val(),
      onlynastool: $("#onlynastool").val(),
      ratio: ratio,
      seeding_time: seeding_time,
      upload_avs: upload_avs,
      size: $("#size").val(),
      tags: $("#tags").val(),
      savepath_key: $("#savepath_key").val(),
      tracker_key: $("#tracker_key").val(),
      downloader: $('input:radio[name=downloader]:checked').val(),
      qb_state: $("#qb_state").val(),
      qb_category: $("#qb_category").val(),
      tr_state: $("#tr_state").val(),
      tr_error_key: $("#tr_error_key").val(),
    };
    $("#add_or_edit_torrent_remove_task_btn").text("保存中").attr("disabled", true);
    ajax_post("update_torrent_remove_task", params, function (ret) {
      $("#modal-torrent-remove-task").modal('hide');
      if (ret.code == 0) {
        $("#add_or_edit_torrent_remove_task_btn").text("保存").attr("disabled", false);
        window_history_refresh();
      } else {
        show_fail_modal(ret.msg, function () {
          $("#modal-torrent-remove-task").modal('show');
          $("#add_or_edit_torrent_remove_task_btn").text("保存").attr("disabled", false);
        });
      }
    });
  }

  // 删除任务
  function delete_torrent_remove_task(tid, name){
    show_confirm_modal("删除下载设置 " + name + " ？", function () {
      hide_confirm_modal();
      ajax_post("delete_torrent_remove_task", { "tid": tid }, function (ret) {
        window_history_refresh();
      });
    });
  }

  // 显示满足条件种子
  function show_remove_torrents_modal(tid){
    ajax_post("get_remove_torrents", { "tid": tid }, function (ret) {
      if (ret.code == 0) {
        let torrents = ret.data;
        let thead = `<thead><tr><th>共${torrents.length}个种子</th></tr></thead>`;
        let tbody = '';
        for (let torrent of torrents) {
          let tb = `<tr><td><span>${torrent.name}</span>
                    <br><span class="badge badge-outline text-blue me-1 mb-1">${torrent.site}</span>
                    <span class="badge badge-outline text-orange me-1 mb-1">${(torrent.size/1024/1024/1024).toFixed(2)} GB</span></td></tr>`;
          tbody = `${tbody}${tb}`;
        }
        tbody = `<tbody>${tbody}</tbody>`;
        $("#table-remove-torrents").empty().append(`${thead}${tbody}`);
        $("#modal-remove-torrents").modal('show');
      } else {
        let content = `<div class="empty"><p class="empty-title">${ret.msg}</p></div>`;
        $("#table-remove-torrents").empty().append(content);
        $("#modal-remove-torrents").modal('show');
      }
    });
  }

  // 单选框事件
  $('input[type=radio][name=downloader]').change(function () {
     let use = this.value;
    show_downloader(use);
  });

  // 删种任务下载器
  function show_downloader(downloader) {
    if (downloader == 'Qb') {
      $("#qb_config_div").show();
      $("#tr_config_div").hide();
      $("#downloader_Qb").prop("checked", true);
    }
    else if (downloader == 'Tr') {
      $("#qb_config_div").hide();
      $("#tr_config_div").show();
      $("#downloader_Tr").prop("checked", true);
    }
  }

  // 立即运行任务
  function run_torrent_remove_now(tid) {
    ajax_post("auto_remove_torrents", { "tid": tid }, function (ret) {
      show_success_modal("任务运行完成！", function () {
        window_history_refresh();
      });
    });
  }
</script>